home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / jemtex2.zip / JEM2TEX.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-14  |  41KB  |  1,210 lines

  1. {$A-,B-,D-,E-,F-,I+,L-,N-,O-,R-,S-,V-}
  2. {Compile with Turbo-Pascal 5.0}
  3. Program Jem2TeX(Input,Output);
  4. {
  5.   This program translates a .JEM file into a .TeX file
  6.  
  7.   Author: Francois Jalbert
  8.               '
  9.   Date: November 1990 
  10.  
  11.   Version: 1.0
  12.  
  13.   Date: January 1991
  14.  
  15.   Version: 1.01
  16.  
  17.   Modifications: - Added \hskip0pt plus0.1em between all Japanese symbols which 
  18.                    improved dramatically line breaks and inter-sentence spacing 
  19.                    since [La]TeX could only add glue between whole Japanese 
  20.                    sentences. 
  21.                  - Extra space after punctuation is now an option since it is 
  22.                    not desirable with MuTeX when the text is to go under the
  23.                    staff. 
  24.                  - Font names now use only small letters to be compatible with 
  25.                    the fontlib program supplied with emTeX. 
  26.                  - Command line parameters now supported.
  27.                  - Run-time parameters now supported.
  28.                  - Updated and improved run-time messages.
  29.  
  30.   Date: April 1991
  31.  
  32.   Version: 2.00
  33.  
  34.   Modifications: - Added four kanjis.
  35.                  - If desired, only standard JIS '83 characters are allowed.
  36.                  - If desired, a % is added at each Japanese end of line.
  37.                  - Three file name extensions .JEM .JPN .JAP now supported.
  38.                  - Default extension is .JEM and the program has been renamed.
  39.                  - Three run-time parameter flags now supported.
  40.                  - Japanese comments not translated anymore for reference.
  41.                  - Hyphenation and glue handled separately for better control.
  42.                  - More clever algorithm for Japanese hyphenation.
  43.                  - Space after some punctuation now obtained with \eeee.
  44.                  - Small space around some punctuation introduced with \eee.
  45.                  - Tiny space between Japanese characters with \ee.
  46.                  - Space between Japanese and Roman with \eeee and \eee.
  47.                  - Symbols separated only by [La]TeX comments are now 
  48.                    recognized as consecutive.
  49.                  - MS-kanji (Shift-JIS) now supported.
  50.  
  51.   Error Levels: 0 - Normal termination.
  52.                 1 - Error.
  53. }
  54. Const
  55.   {Highest Bitmap number in JIS24}
  56.   BitmapMax=7806;
  57.   {Highest font number}
  58.   FontMax=60; {Floor of 7806 Div 128}
  59.   {Highest size number}
  60.   SizeMax=7; {magsteps are 0, 0.5, 1, 2, 3, 4, 5}
  61.   {File name extensions in priority order}
  62.   Extension1:String[4]='.jem';
  63.   Extension2:String[4]='.jpn';
  64.   Extension3:String[4]='.jap';
  65.   {Run-time flag of all the same length}
  66.   RunFlag1:String[7]='JEM2TEX';
  67.   RunFlag2:String[7]='JPN2TEX';
  68.   RunFlag3:String[7]='JAP2TEX';
  69.   {Parameter flag}
  70.   Flag1='/'; {DOS style}
  71.   Flag2='-'; {UNIX style}
  72.   {Parameter keywords in approximate decreasing length order}
  73.   Space1:String[10]='EXTRASPACE';
  74.   Space2:String[5]='EXTRA';
  75.   Space3:String[5]='SPACE';
  76.   NoSpace1:String[12]='NOEXTRASPACE';
  77.   NoSpace2:String[7]='NOEXTRA';
  78.   NoSpace3:String[7]='NOSPACE';
  79.   Percent1:String[7]='COMMENT';
  80.   Percent2:String[7]='PERCENT';
  81.   Percent3:String[3]='EOL';
  82.   NoPercent1:String[9]='NOCOMMENT';
  83.   NoPercent2:String[9]='NOPERCENT';
  84.   NoPercent3:String[5]='NOEOL';
  85.   EUC1:String[3]='EUC';
  86.   NoEUC1:String[7]='MSKANJI';
  87.   NoEUC2:String[8]='SHIFTJIS';
  88.   Extended1:String[8]='EXTENDED';
  89.   Standard1:String[8]='STANDARD';
  90.   LaTeX1:String[5]='LATEX';
  91.   TeX1:String[5]='MUTEX';
  92.   TeX2:String[3]='TEX';
  93.   One1:String[4]='1000';
  94.   Two1:String[4]='1095';
  95.   Three1:String[4]='1200';
  96.   Four1:String[4]='1440';
  97.   Five1:String[4]='1728';
  98.   Six1:String[4]='2074';
  99.   Seven1:String[4]='2488';
  100.   One2:String[3]='0.0';
  101.   Two2:String[3]='0.5';
  102.   Three2:String[3]='1.0';
  103.   Four2:String[3]='2.0';
  104.   Five2:String[3]='3.0';
  105.   Six2:String[3]='4.0';
  106.   Seven2:String[3]='5.0';
  107.   One3:String[1]='0';
  108.   Three3:String[1]='1';
  109.   Four3:String[1]='2';
  110.   Five3:String[1]='3';
  111.   Six3:String[1]='4';
  112.   Seven3:String[1]='5';
  113.  
  114. Type
  115.   InFileType=File Of Byte;
  116.   OutFileType=Text;
  117.   BitmapRange=1..BitmapMax;
  118.   FontRange=0..FontMax;
  119.   FontType=Array [FontRange] Of Boolean;
  120.   SizeRange=1..SizeMax;
  121.   FontsType=Array [SizeRange] Of FontType;
  122.   {Run time parameters}
  123.   RunTimeType=Record
  124.                 FileName,Extension:String;
  125.                 ExtraSpace,Percent,LaTeX,EUC,Extended:Boolean;
  126.                 Size:SizeRange;
  127.               End;
  128.   {Japanese punctuation information}
  129.   PunctuationType=Record
  130.                     {Indicates .,!? present}
  131.                     OldMajorEOL,NewMajorEOL:Boolean;
  132.                     {Indicates :; present}
  133.                     OldMinorEOL,NewMinorEOL:Boolean;
  134.                     {Indicates `"([< and other openings present}
  135.                     OldOpening,NewOpening:Boolean;
  136.                     {Indicates '")]> and other closings present}
  137.                     OldClosing,NewClosing:Boolean;
  138.                     {Indicates Japanese center dot present}
  139.                     OldCenterDot,NewCenterDot:Boolean;
  140.                     {Indicates Hiragana, Katakana, or Kanji present}
  141.                     OldJapanese,NewJapanese:Boolean
  142.                   End;
  143.   {Scanning Information}
  144.   ScanningType=Record
  145.                  {Current pass terminated}
  146.                  Done:Boolean;
  147.                  {Indicates the current pass must produce output}
  148.                  Echo:Boolean;
  149.                  {Indicates the current line is a comment}
  150.                  Comment:Boolean;
  151.                  {Indicates current Bitmap immediately followed previous one}
  152.                  Immediate:Boolean;
  153.                  {Indicates the last Roman character was a letter or digit}
  154.                  WasLetter:Boolean;
  155.                  {Used for glue after a bitmap and before a roman}
  156.                  RomanMajorEOL,RomanMinorEOL,RomanOpening:Boolean;
  157.                  {Non-comment Bitmap found}
  158.                  Found:Boolean;
  159.                  {Processing the first character on the line which could be %}
  160.                  First:Boolean;
  161.                  {Comment line which may contain Bitmaps}
  162.                  CommentLine:String;
  163.                  {Current JIS24 Bitmap number}
  164.                  Bitmap:BitmapRange;
  165.                  {Roman or first part of Bitmap read}
  166.                  Data1:Byte
  167.                End;
  168.  
  169. Var
  170.   {Input and Output file names}
  171.   InFile:InFileType;
  172.   OutFile:OutFileType;
  173.   {Run time parameters}
  174.   RunTime:RunTimeType;
  175.   {JemTeX fonts used}
  176.   Fonts:FontsType;
  177.  
  178. {------------------------------ EchoParameters -------------------------------}
  179.  
  180. Procedure EchoParameters(Var EchoFile:Text; Var RunTime:RunTimeType);
  181. {Echoes the current parameters in EchoFile}
  182. Begin
  183. With RunTime Do
  184.   Begin
  185.   Write(EchoFile,'File='+FileName);
  186.   If ExtraSpace Then Write(EchoFile,'  Space')
  187.   Else Write(EchoFile,'  No Space');
  188.   If Percent Then Write(EchoFile,'  Added %')
  189.   Else Write(EchoFile,'  No Added %');
  190.   If LaTeX Then Write(EchoFile,'  LaTeX')
  191.   Else Write(EchoFile,'  TeX');
  192.   If EUC Then Write(EchoFile,'  EUC')
  193.   Else Write(EchoFile,'  MS-kanji');
  194.   If Extended Then Write(EchoFile,'  Extended')
  195.   Else Write(EchoFile,'  Standard');
  196.   Write(EchoFile,'  Font Size=');
  197.   Case Size Of
  198.     1:Write(EchoFile,'1000');
  199.     2:Write(EchoFile,'1095');
  200.     3:Write(EchoFile,'1200');
  201.     4:Write(EchoFile,'1440');
  202.     5:Write(EchoFile,'1728');
  203.     6:Write(EchoFile,'2074');
  204.     7:Write(EchoFile,'2488')
  205.     End;
  206.   Writeln(EchoFile,'.')
  207.   End
  208. End;
  209.  
  210. {------------------------------- GetParameters -------------------------------}
  211.  
  212. Procedure SimpleQuery(Title,ChoiceA,ChoiceB:String; Var Answer:Boolean);
  213. Var
  214.   JChar:Char;
  215.   Valid:Boolean;
  216. Begin
  217. Repeat
  218.   Valid:=True;
  219.   Writeln(Title+':');
  220.   Writeln('   a)  '+ChoiceA);
  221.   Writeln('   b)  '+ChoiceB);
  222.   Write('Your choice? ');
  223.   Readln(JChar);
  224.   JChar:=UpCase(JChar);
  225.   If JChar='A' Then Answer:=True
  226.   Else
  227.     If JChar='B' Then Answer:=False
  228.     Else
  229.       Begin Valid:=False; Write(Chr(7)) End
  230. Until Valid;
  231. Writeln
  232. End;
  233.  
  234. Procedure SizeQuery(Var Size:SizeRange)